//
//  CPSCVideoShortVideoTBCell.m
//  CPSCustomer
//
//  Created by codew on 9/2/21.
//  Copyright © 2021 dgg_hzk. All rights reserved.
//

#import "CPSCVideoShortVideoTBCell.h"

@interface CPSCVideoShortVideoTBCell ()

@property (nonatomic, strong) UIView * viewContentSuper;
@property (nonatomic, strong) UIView * viewContent;

// 用户
@property (nonatomic, strong) UIView * viewUser;
//
@property (nonatomic, strong) UIView * viewBottom;
//
@property (nonatomic, strong) UIView * viewCoverSuper;
// ================================================================
/** 用户 头像 + 姓名 + 关注 */
@property (nonatomic, strong) UIImageView * imageViewUserIcon;
@property (nonatomic, strong) UILabel * lblName;
@property (nonatomic, strong) UIButton * btnFollow;
/**标题 */
@property (nonatomic, strong) UILabel * lblSummary;
/**封面图*/
@property (nonatomic, strong) UIImageView * imageViewCover;
// 观看次数
@property (nonatomic, strong) UILabel * lblViewsNumber;
// 时长
@property (nonatomic, strong) UILabel * lblTotalTime;
// 点赞
@property (nonatomic,strong) UIButton *btnPraise;
// 评论
@property (nonatomic,strong) UIButton *btnComment;



@end

@implementation CPSCVideoShortVideoTBCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}


- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self initSubviews];
        [self makeContraints];
    }
    return self;
}



- (void)updateCellWithItem:(id)item
{
    
}


#pragma mark - private initUI
//MARK:初始化
- (void)initSubviews {
    
    self.backgroundColor = [UIColor colorWithHexString:@"#F5F5F5"];
    [self addSubview:self.viewContentSuper];
    [self.viewContentSuper addSubview:self.viewContent];
        
    // 头像+名字+关注================================================================
    [self.viewContent addSubview:self.viewUser];
    [self.viewUser addSubview:self.imageViewUserIcon];
    [self.viewUser addSubview:self.lblName];
    [self.viewUser addSubview:self.btnFollow];
    
    //视频文字内容 ================================================================
    [self.viewContent addSubview:self.lblSummary];
    
    //视频封面+观看次数+时长 ================================================================
    [self.viewContent addSubview:self.viewCoverSuper];
    [self.viewCoverSuper addSubview:self.imageViewCover];
    [self.viewCoverSuper addSubview:self.lblTotalTime];
    [self.viewCoverSuper addSubview:self.lblViewsNumber];
    
    // 点赞+评论 ================================================================
    [self.viewContent addSubview:self.viewBottom];
    [self.viewBottom addSubview:self.btnPraise];
    [self.viewBottom addSubview:self.btnComment];
    
    
    [self deBugUI];
}

- (void)makeContraints
{
    [self.viewContentSuper mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.right.mas_equalTo(0);
        make.bottom.mas_equalTo(-10);
    }];
    
    [self.viewContent mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.bottom.mas_equalTo(0);
        make.right.mas_equalTo(-16);
        make.left.mas_equalTo(16);
    }];
    
    
    // 头像+名字+关注 ==============================================================================================================================
    [self.viewUser mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.right.left.mas_equalTo(0);
        make.height.mas_equalTo(64);
    }];
    [self.imageViewUserIcon mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(0);
        make.height.width.mas_equalTo(34);
        make.centerY.equalTo(self.viewUser);
    }];
    [self.lblName mas_makeConstraints:^(MASConstraintMaker *make) {

        make.centerY.equalTo(self.viewUser);
        make.left.equalTo(self.imageViewUserIcon.mas_right).offset(8);
    }];
    [self.btnFollow mas_makeConstraints:^(MASConstraintMaker *make) {

        make.right.mas_equalTo(0);
        make.width.mas_equalTo(72);
        make.height.mas_equalTo(32);
        make.centerY.equalTo(self.viewUser);
    }];

    //视频文字内容  ==============================================================================================================================
    [self.lblSummary mas_makeConstraints:^(MASConstraintMaker *make) {
                
        make.top.equalTo(self.viewUser.mas_bottom).offset(0);
        make.right.left.mas_equalTo(0);
    }];
            
    //点赞+评论  ==============================================================================================================================
    [self.viewBottom mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.height.mas_equalTo(44);
        make.right.bottom.left.mas_equalTo(0);
    }];
    
    [self.btnPraise mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(0);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(20);
        make.centerY.equalTo(self.viewBottom);
    }];
    
    [self.btnComment mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.btnPraise.mas_right).offset(20);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(20);
        make.centerY.equalTo(self.viewBottom);
    }];
    
    //视频封面+观看次数+时长  ========================================================================================================================
    [self.viewCoverSuper mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.mas_equalTo(0);
        make.top.equalTo(self.lblSummary.mas_bottom).offset(10);
        make.bottom.equalTo(self.viewBottom.mas_top);
    }];
    
    [self.imageViewCover mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.left.bottom.right.mas_equalTo(0);
    }];
    
    [self.lblViewsNumber mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(10);
        make.bottom.mas_equalTo(-10);
    }];
    
    [self.lblTotalTime mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(-10);
        make.bottom.mas_equalTo(-10);
    }];

    
}

- (void)deBugUI
{
//    self.viewContent.backgroundColor = [UIColor yellowColor];
    
    self.imageViewUserIcon.image = [UIImage imageNamed:@"c"];
    self.lblName.text = @"杨钥均";    
    self.lblSummary.text = @"我们赖以生存的地球家园正在遭受新一轮的侵袭，点开视频看详情，我知道你会点我们赖以生存的地球家园正在遭受新一轮的侵袭，点开视频看详情，我知道你会点";
    
    [self.btnPraise setTitle:@"100" forState:UIControlStateNormal];
    [self.btnComment setTitle:@"100" forState:UIControlStateNormal];
    
    
//    self.viewUser.backgroundColor = [UIColor yellowColor];
//    self.lblSummary.backgroundColor = [UIColor redColor];
//    self.viewBottom.backgroundColor = UIColor.blackColor;
//    self.viewCoverSuper.backgroundColor = UIColor.grayColor;
    
    self.imageViewCover.image = [UIImage imageNamed:@"op"];
    self.lblTotalTime.text = @"05:30";
    self.lblViewsNumber.text = @"3000次观看";
}

#pragma mark - Getter Setter

- (UILabel *)lblName
{
    if (!_lblName) {
        
        UILabel * lblZy = [[UILabel alloc] init];
        lblZy.textColor = [UIColor colorWithHexString:@"#222222"];
        lblZy.font = [UIFont systemFontOfSize:14];
        lblZy.textAlignment = NSTextAlignmentLeft;
        
        _lblName = lblZy;
    }
    
    return _lblName;
}

- (UIImageView *)imageViewUserIcon
{
    if (!_imageViewUserIcon) {
        
        UIImageView * imageViewIcon = [[UIImageView alloc] init];
        imageViewIcon.contentMode = UIViewContentModeScaleAspectFill;
        imageViewIcon.layer.cornerRadius = 17;
        imageViewIcon.layer.masksToBounds = YES;
        
        _imageViewUserIcon = imageViewIcon;
    }
    return _imageViewUserIcon;
}

- (UIButton *)btnFollow
{
    if (!_btnFollow) {
        
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:CPSICONFONT_CONFIG(@"\U000e1111", 10, UIColor.whiteColor) forState:UIControlStateNormal];
        [btn setTitle:@"关注" forState:UIControlStateNormal];
        [btn setTitleColor:UIColor.whiteColor forState:UIControlStateNormal];
        btn.backgroundColor = [UIColor colorWithHexString:@"#4974F5"];//
        btn.titleLabel.font = [UIFont systemFontOfSize:13 weight:1];
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
        btn.layer.cornerRadius = 4;
        btn.layer.masksToBounds = YES;
        btn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, -5);
        
        _btnFollow = btn;
    }
    
    return _btnFollow;
}


- (UILabel *)lblSummary
{
    if (!_lblSummary) {
        
        UILabel * lblZy = [[UILabel alloc] init];
        lblZy.textColor = [UIColor colorWithHexString:@"#1A1A1A"];
        lblZy.font = [UIFont systemFontOfSize:18 weight:1];
        lblZy.textAlignment = NSTextAlignmentLeft;
        lblZy.numberOfLines = 2;
        
        _lblSummary = lblZy;
    }
    
    return _lblSummary;
}

- (UIImageView *)imageViewCover
{
    if (!_imageViewCover) {
        
        UIImageView * imageViewIcon = [[UIImageView alloc] init];
        imageViewIcon.contentMode = UIViewContentModeScaleAspectFill;
//        imageViewIcon.layer.cornerRadius = 20;
//        imageViewIcon.layer.masksToBounds = YES;
        
        _imageViewCover = imageViewIcon;
    }
    return _imageViewCover;
}


- (UILabel *)lblViewsNumber
{
    if (!_lblViewsNumber) {
        
        UILabel * lblZy = [[UILabel alloc] init];
        lblZy.textColor = UIColor.whiteColor;
        lblZy.font = [UIFont systemFontOfSize:12];
        lblZy.textAlignment = NSTextAlignmentLeft;
        
        _lblViewsNumber = lblZy;
    }
    
    return _lblViewsNumber;
}
- (UILabel *)lblTotalTime
{
    if (!_lblTotalTime) {
        
        UILabel * lblZy = [[UILabel alloc] init];
        lblZy.textColor = UIColor.whiteColor;
        lblZy.font = [UIFont systemFontOfSize:12];
        lblZy.textAlignment = NSTextAlignmentLeft;
        
        _lblTotalTime = lblZy;
    }
    
    return _lblTotalTime;
}

- (UIButton *)btnPraise
{
    if (!_btnPraise) {
        
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];

        [btn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
        [btn setTitleColor:[UIColor colorWithHexString:@"#4974F5"] forState:UIControlStateSelected];
        [btn setImage:CPSICONFONT_CONFIG(@"\U000e1054", 18, [UIColor colorWithHexString:@"#999999"]) forState:UIControlStateNormal];
        [btn setImage:CPSICONFONT_CONFIG(@"\U000e1054", 18, [UIColor colorWithHexString:@"#4974F5"]) forState:UIControlStateSelected];
        
        btn.backgroundColor = [UIColor whiteColor];
        btn.titleLabel.font = [UIFont systemFontOfSize:15];
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
//        btn.titleEdgeInsets = UIEdgeInsetsMake(0, 5, 0, -5);
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0);//UIEdgeInsetsMake(<#CGFloat top#>, <#CGFloat left#>, <#CGFloat bottom#>, <#CGFloat right#>)
//        [btn addTarget:self action:@selector(<#certain#>) forControlEvents:UIControlEventTouchUpInside];
        
        
        _btnPraise = btn;
    }
    
    return _btnPraise;
}

- (UIButton *)btnComment
{
    if (!_btnComment) {
        
        UIButton * btn = [UIButton buttonWithType:UIButtonTypeCustom];
        
        
        [btn setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateNormal];
        [btn setImage:CPSICONFONT_CONFIG(@"\U000e1031", 18, [UIColor colorWithHexString:@"#999999"]) forState:UIControlStateNormal];
        
        btn.backgroundColor = [UIColor whiteColor];
        btn.titleLabel.font = [UIFont systemFontOfSize:15];
        btn.titleLabel.textAlignment = NSTextAlignmentCenter;
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 0);
        [btn addTarget:self action:@selector(certain) forControlEvents:UIControlEventTouchUpInside];
        
        
        _btnComment = btn;
    }
    
    return _btnComment;
}

- (UIView *)viewContent
{
    
    if (!_viewContent) {
        
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = UIColor.whiteColor;//[UIColor colorWithHexString:@"#F5F5F5"];;
        view.clipsToBounds = YES;
        
        _viewContent = view;
    }
    return _viewContent;
}


- (UIView *)viewContentSuper
{
    
    if (!_viewContentSuper) {
        
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        view.clipsToBounds = YES;
        
        _viewContentSuper = view;
    }
    return _viewContentSuper;
}

- (UIView *)viewUser
{
    
    if (!_viewUser) {
        
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        view.clipsToBounds = YES;
        
        _viewUser = view;
    }
    return _viewUser;
}


- (UIView *)viewBottom
{
    
    if (!_viewBottom) {
        
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        view.clipsToBounds = YES;
        
        _viewBottom = view;
    }
    return _viewBottom;
}

- (UIView *)viewCoverSuper
{
    
    if (!_viewCoverSuper) {
        
        UIView * view = [[UIView alloc] init];
        view.backgroundColor = [UIColor whiteColor];
        view.clipsToBounds = YES;
        
        view.layer.cornerRadius = 6;
        view.layer.masksToBounds = YES;
        
        _viewCoverSuper = view;
    }
    return _viewCoverSuper;
}


@end
